﻿$(document).ready(function () {
    //日期選擇器 datepicker
    //-----------------------------------------------------------------------
    $(".datepicker").datepicker({ changeMonth: true,
        changeYear: true,yearRange: '-100:+10'
    });
});


function ChkEmail() {
    var mail_check = /.+@.+\..+/;
    if (!$("#email").val().match(mail_check)) {
        alert("請輸入正確的E-Mail!");
        $("#email").focus();
    }
}

function ChkPwd() {
    if ($("#password").val() != null && $("#confirm").val() != null) {
        if ($("#password").val() != $("#confirm").val()) {
            alert("請再次確認密碼是否相同!");
            
        }
    }

}

function addmyfavorite2(sn) {
    if ($("#mguid_" + sn).val() == "00000000-0000-0000-0000-000000000000") {
        alert('請先登入，才可使用我的最愛功能喔!')
    }
    else {
        var jsonstring = { "mguid": $("#mguid_" + sn).val(),
            "mkguid": $("#mkguid_" + sn).val(),
            "productid": $("#productid_" + sn).val(),
            "specid": $("#specid_" + sn).val()
        };
        $.ajax({
            type: "POST",
            traditional: true,
            url: "/member/add_my_favorite",
            data: jsonstring,
            dataType: "json",
            success: function (data) {
                if (data.code == "200") {
                    alert("新增成功!"); location.reload();
                }
                else
                    alert(data.response); location.reload();
            }
        });
    }
}


/*動態雙層選單 S--------------------------------------------------------*/
//商品規格及數量

function makeSublist(parent, child) {
    $("body").append("<select style='display:none' id='" + parent + child + "'></select>");
    $('#' + parent + child).html($("#" + child + " option"));
    var parentValue = $('#' + parent).attr('value');
    $('#' + child).html($("#" + parent + child + " .sub_" + parentValue).clone());
    $('#' + parent).change(function () {
        var parentValue = $('#' + parent).attr('value');
        $('#' + child).html($("#" + parent + child + " .sub_" + parentValue).clone());
        if (parentValue == "0")
            $('#' + child).html("<option value='0'>請選擇</option>");

    });
}

/*分享 S-----------------------------------------------------------------*/

function shareArticle() {
    var u = location.href;
    var t = document.title;
    $('#share_f').click(function () {
        window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t));
        return false;
    });
    $('#share_t').click(function () {
        window.open('http://twitter.com/home/?status='.concat(encodeURIComponent(t)).concat(' ').concat(encodeURIComponent(u)));
        return false;
    });
    $('#share_p').click(function () {
        window.open('http://www.plurk.com/?qualifier=shares&status='.concat(encodeURIComponent(u)).concat(' ').concat('(').concat(encodeURIComponent(t)).concat(')'));
        return false;
    });
    $('#share_s').click(function () {
        window.open('http://v.t.sina.com.cn/share/share.php?title='.concat(encodeURIComponent(u)).concat('%20').concat(encodeURIComponent(t)).concat('&#41;'));
        return false;
    });



}

/*分享 E-----------------------------------------------------------------*/

/*TopDm 自動輪撥 S------------------------------------------------------*/
function TopDm() {
    topDmTimer = setTimeout(topDmAutoRun, 5000);
    // 當滑鼠移入時停止計時器；反之則啟動
    $('#topDm').mouseover(function () {
        clearTimeout(topDmTimer);
    });
    $('#topDm').mouseout(function () {
        topDmTimer = setTimeout(topDmAutoRun, 5000);
    });
}
/*TopDm 自動輪撥 E-------------------------------------------------------*/

/*TopDm 自動輪撥 S-------------------------------------------------------*/
function topDmAutoRun() {
    var topDm = $('#topDm'),
		curr = $('#topDm li a.curr').parent('li'),
		posIndex = curr.index(),
		totle = $('#topDm li').size();

    topDm.find('.curr').removeClass('curr');
    if ((posIndex + 1 - totle) !== 0) {
        topDm.find('.channel').eq(posIndex + 1).addClass('curr');
        curr.next().find('a').addClass('curr');
    }
    else {
        topDm.find('.channel').eq(0).addClass('curr');
        $('#topDm li:first a').addClass('curr');
    }
    topDmTimer = setTimeout(topDmAutoRun, 5000);
}
/*TopDm 自動輪撥 E------------------------------------------------------*/

/*Tab S-----------------------------------------------------------------*/
function Tab() {
    $('.tabBox > ul li').mouseover(function () {
        var tabBox = $(this).parents('.tabBox');
        var tabIndex = $(this).index();
        tabBox.find('.curr').removeClass('curr').end().find('.channel').eq(tabIndex).addClass('curr');
        $(this).find('a').addClass('curr');
    });
    $('.tabBox > ul a').click(function (e) { e.preventDefault(); });
}
/*Tab E-----------------------------------------------------------------*/

function GetResponse(msg) {
    if (msg != '')
        alert(msg);
}

function searchTag(key) {
    $("#taglist tbody tr").hide();
    $(".ttitle").each(function () {
        if ($(this).html().indexOf(key) > -1)
            $(this).parent().show();
    });
}

function sendEdm() {
    var mail_check = /.+@.+\..+/;
    if ($("#edm").val().match(mail_check)) {
        var jsonstring = { "email": $("#edm").val() };
        $.ajax({
            type: "POST",
            traditional: true,
            url: "/api/setedm",
            data: jsonstring,
            dataType: "json",
            success: function (data) {
                if (data.code == "200") {
                    alert("新增成功!");
                    $("#edm").val('Sign Up For Email');
                }
                else
                    alert(data.response);
            }
        });
    }
    else
        alert('請輸入正確的email!!');
}